<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <link th:href="@{https://cdn.bootcss.com/twitter-bootstrap/3.0.1/css/bootstrap.min.css}" rel="stylesheet">
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<!--<span th:text="${pageInfo.list}"></span>-->
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <h3 class="text-center">
                增加评论
            </h3>
            <form class="form-horizontal" role="form" id="formInfo">
                <span id="errInfo" style="color: red"></span>
                <input type="hidden" name="newsid" th:value="${id}" id="newsId">
                <div class="form-group">
                    <label for="content" class="col-sm-2 control-label">评论内容</label>
                    <div class="col-sm-10">
                        <textarea type="text" class="form-control" id="content" name="content"></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label for="commentPerson" class="col-sm-2 control-label">评论人</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="commentPerson" name="anthor" />
                    </div>
                </div>



                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="button" class="btn btn-default" onclick="addcomment()">提交</button>
                        <button type="button" class="btn btn-default" onclick="history.back()">返回</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    function addcomment() {

        var data=$("#formInfo").serialize();


       $.ajax({
           url:"/news/addComment",
           data:data,
           type:"post",
           dataType:"json",
           success(result){
               if (result.code==0) {
                   location.href="/news/index"
               }else {
                   $("#errInfo").html(result.msg)
               }
           },
           error(){
               alert("数据回传失败 请联系管理员")
           }


       })
    }

</script>


</body>
</html>